﻿namespace Sidvall.WorkItemManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class WorkItemWorkCondition : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition
    {
        #region Public Members

        #region ConditionContext

        private string _ConditionContext;
        partial void OnBeforeConditionContextPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterConditionContextPropertyChanged();
        public string ConditionContext
        { 
            get
            {
                return _ConditionContext;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ConditionContext = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ConditionContext);
                    OnBeforeConditionContextPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ConditionContext", eventData.Value, true, true);
                        OnAfterConditionContextPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region GroupId

        private string _GroupId;
        partial void OnBeforeGroupIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterGroupIdPropertyChanged();
        public string GroupId
        { 
            get
            {
                return _GroupId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _GroupId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _GroupId);
                    OnBeforeGroupIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("GroupId", eventData.Value, true, true);
                        OnAfterGroupIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region InvalidAction

        private global::Sidvall.WorkItemManager.Workflow.ThreadAction _InvalidAction;
        partial void OnBeforeInvalidActionPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.ThreadAction> eventData);
        partial void OnAfterInvalidActionPropertyChanged();
        public global::Sidvall.WorkItemManager.Workflow.ThreadAction InvalidAction
        { 
            get
            {
                return _InvalidAction;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _InvalidAction = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.ThreadAction> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.ThreadAction>(value, _InvalidAction);
                    OnBeforeInvalidActionPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("InvalidAction", eventData.Value, true, true);
                        OnAfterInvalidActionPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region IsEnabled

        private bool _IsEnabled;
        partial void OnBeforeIsEnabledPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsEnabledPropertyChanged();
        public bool IsEnabled
        { 
            get
            {
                return _IsEnabled;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _IsEnabled = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsEnabled);
                    OnBeforeIsEnabledPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("IsEnabled", eventData.Value, true, true);
                        OnAfterIsEnabledPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region IsEnabledOnRetry

        private bool _IsEnabledOnRetry;
        partial void OnBeforeIsEnabledOnRetryPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsEnabledOnRetryPropertyChanged();
        public bool IsEnabledOnRetry
        { 
            get
            {
                return _IsEnabledOnRetry;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _IsEnabledOnRetry = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsEnabledOnRetry);
                    OnBeforeIsEnabledOnRetryPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("IsEnabledOnRetry", eventData.Value, true, true);
                        OnAfterIsEnabledOnRetryPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WorkConditionId

        private long _WorkConditionId;
        partial void OnBeforeWorkConditionIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterWorkConditionIdPropertyChanged();
        public long WorkConditionId
        { 
            get
            {
                return _WorkConditionId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WorkConditionId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _WorkConditionId);
                    OnBeforeWorkConditionIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WorkConditionId", eventData.Value, true, true);
                        OnAfterWorkConditionIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WorkItemId

        private long _WorkItemId;
        partial void OnBeforeWorkItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterWorkItemIdPropertyChanged();
        public long WorkItemId
        { 
            get
            {
                return _WorkItemId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WorkItemId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _WorkItemId);
                    OnBeforeWorkItemIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WorkItemId", eventData.Value, true, true);
                        OnAfterWorkItemIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public WorkCondition WorkCondition { get; set; }
        public WorkItem WorkItem { get; set; }
        #region LoadWorkConditionAsync

        public async System.Threading.Tasks.Task<WorkCondition> LoadWorkConditionAsync()
        {
            return await LoadWorkConditionAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkCondition> LoadWorkConditionAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.WorkItemManager.Data.Fields.WorkConditionField, global::Sidvall.WorkItemManager.Data.Relations.WorkConditionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.LoadWorkConditionAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.WorkCondition;
        }
        public WorkCondition LoadWorkCondition(WorkCondition item)
        {
            LoadInstanceField("WorkCondition", item, true, false);
            return item;
        }

        #endregion
        #region LoadWorkItemAsync

        public async System.Threading.Tasks.Task<WorkItem> LoadWorkItemAsync()
        {
            return await LoadWorkItemAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItem> LoadWorkItemAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.WorkItemManager.Data.Fields.WorkItemField, global::Sidvall.WorkItemManager.Data.Relations.WorkItemRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.LoadWorkItemAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.WorkItem;
        }
        public WorkItem LoadWorkItem(WorkItem item)
        {
            LoadInstanceField("WorkItem", item, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public WorkItemWorkCondition Copy()
        {
            return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.Copy(this);
        }
        public WorkItemWorkCondition Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition item)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.Import(this, item);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.Import(this, item, settings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<WorkItemWorkCondition> SaveItemAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.SaveItemAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItemWorkCondition> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.SaveItemAsync(this, mode).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItemWorkCondition> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.SaveItemAsync(this, settings).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItemWorkCondition> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.SaveItemAsync(this, settings, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.Initialize(this, settings);
        }

        #endregion

        #region IWorkItemWorkCondition Members

        string global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.ConditionContext
        {
            get
            {
                return this._ConditionContext;
            }
            set
            {
                this._ConditionContext = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.GroupId
        {
            get
            {
                return this._GroupId;
            }
            set
            {
                this._GroupId = value;
            }
        }
        global::Sidvall.WorkItemManager.Workflow.ThreadAction global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.InvalidAction
        {
            get
            {
                return this._InvalidAction;
            }
            set
            {
                this._InvalidAction = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.IsEnabled
        {
            get
            {
                return this._IsEnabled;
            }
            set
            {
                this._IsEnabled = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.IsEnabledOnRetry
        {
            get
            {
                return this._IsEnabledOnRetry;
            }
            set
            {
                this._IsEnabledOnRetry = value;
            }
        }
        long global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.WorkConditionId
        {
            get
            {
                return this._WorkConditionId;
            }
            set
            {
                this._WorkConditionId = value;
            }
        }
        long global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.WorkItemId
        {
            get
            {
                return this._WorkItemId;
            }
            set
            {
                this._WorkItemId = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IWorkCondition global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.WorkCondition
        {
            get
            {
                return this.WorkCondition;
            }
            set
            {
                this.WorkCondition = (WorkCondition)value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IWorkItem global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.WorkItem
        {
            get
            {
                return this.WorkItem;
            }
            set
            {
                this.WorkItem = (WorkItem)value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public WorkItemWorkCondition()
        {
        }
        public WorkItemWorkCondition(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public WorkItemWorkCondition(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.Initialize(this);
        }

        #endregion
    }
}